package com.zyl.Ecs.common.domain.auth.ext;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.zyl.Ecs.common.domain.auth.bean.Role;
import com.zyl.Ecs.common.domain.auth.vo.RoleVO;
import com.zyl.Ecs.common.utils.CUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.List;

/**
 * @version v1.0
 * @ProjectName: Ecs
 * @Package: com.zyl.Ecs.auth.domain.dto
 * @ClassName: RoleDto
 * @Description TODO (角色扩展类)
 * @Author 翟玉龙
 * @Date 2024/12/4-16:58
 */
@Data
@SuperBuilder
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "base_role")
public class RoleExt extends Role {

    /**
     * 角色包含的权限id列表（入参）
     */
    @TableField(exist = false)
    private List<PermissionExt> permissions;

    /**
     * 角色包含的所有权限（出参）
     */
    @TableField(exist = false)
    @JsonProperty("permissionIds")
    private List<Integer> permissionIds;

    public static RoleExt toExt(Role role) {
        return CUtil.copyBean(role, RoleExt.class);
    }

    public static RoleExt toExt(RoleVO roleVO) {
        return RoleExt.builder()
                .id(roleVO.getId())
                .name(roleVO.getName())
                .permissionIds(roleVO.getPermissionIds())
                .build();
    }
}
